package com.yunjing.mvparmsdemo.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.yunjing.mvparmsdemo.mvp.api.entity.NewListEntity;
import com.yunjing.mvparmsdemo.mvp.api.service.CommonService;
import com.yunjing.mvparmsdemo.mvp.contract.NewContract;
import com.yunjing.mvparmsdemo.mvp.api.Api;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 01/30/2023 10:04
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class NewModel extends BaseModel implements NewContract.Model {

    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    private static final String TAG = "NewModelTag";

    @Inject
    public NewModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public Observable<NewListEntity> onGetNewListRequest(int page) {
        return mRepositoryManager.obtainRetrofitService(CommonService.class)
                .onNewListRequest(Api.NewKey, 15, page)
                .flatMap((Function<NewListEntity, ObservableSource<NewListEntity>>) response -> Observable.just(response));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }


}